package de.koller.balance.scene.uniqueCube;

import de.koller.aframe.gl.ATexture;
import de.koller.aframe.gl.Camera;
import de.koller.altitude.render.textures.GridTexture;
import de.koller.balance.obj.FormableCube;
import de.koller.balance.render.BRenderExt;
import de.koller.oceanFramework.math.RVec3;
import java.util.Random;
import org.lwjgl.opengl.GL11;

public class UniqueCubeScene extends BRenderExt {
	private final ATexture grid = new GridTexture();
	public final Camera camera = new Camera();
	
	private final FormableCube yellowCube = new FormableCube();
	
	private void initCamera() {
		commonUses.setUpPerspective();
		
		GL11.glPushMatrix();
		camera.position.set( -.5f, 3, 5 );
		camera.setLookAt( new RVec3( 0, 0, 0 ) );
		camera.up.set( 0, 1, 0 );
		camera.transformGL();
	}
	
	private void popCamera() {
		GL11.glPopMatrix();
	}

	private void renderYellowCube( float x, float z ) {
		grid.bindAnisotrophic();
		Random rnd = new Random( (long)(x * 1351f + z*2f) );
		GL11.glColor3f( rnd.nextFloat(), rnd.nextFloat(), rnd.nextFloat() );
		yellowCube.render( x, .3f, z, .6f, .6f, .6f );
	}
	
	@Override
	public void renderSzene() {
		initCamera();
		
		for( float x = -150; x < 150; x += .8f )
			for( float z = -200; z < 10; z += .8f )
				renderYellowCube( x, z );
		
		popCamera();
	}
		
}
